-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(db-postgres): prevent indexes from changing name on HMR #10154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DanRibbens
approved these changes
Dec 27, 2024
DanRibbens
pushed a commit
that referenced
this pull request
Dec 27, 2024
Based on #10154 If the actual database schema is not changed (no new columns, enums, indexes, tables) - skip calling Drizzle push. This, potentially can significantly reduce overhead on reloads in development mode especially when using remote databases. If for whatever reason you need to preserve the current behavior you can use `PAYLOAD_FORCE_DRIZZLE_PUSH=true` env flag.
🚀 This is included in version v3.12.0 |
kendelljoseph
pushed a commit
that referenced
this pull request
Feb 21, 2025
As we didn't reset our `adapter.indexes` state, on every HMR reload we incremented every single index name with the `buildIndexName`: https://github.com/payloadcms/payload/blob/466f109152bc6bf9a67e7d7bafd38c7d57a881de/packages/drizzle/src/utilities/buildIndexName.ts#L3-L24 I found this while debugging our internal SQL schema: Before reload: ```ts "payload_preferences": { "name": "payload_preferences", "columns": { "id": { "name": "id", "type": "serial", "primaryKey": true }, "key": { "name": "key", "type": "varchar" }, "value": { "name": "value", "type": "jsonb" }, "updatedAt": { "name": "updated_at", "type": "timestamp", "defaultNow": true, "mode": "string", "notNull": true, "precision": 3, "withTimezone": true }, "createdAt": { "name": "created_at", "type": "timestamp", "defaultNow": true, "mode": "string", "notNull": true, "precision": 3, "withTimezone": true } }, "foreignKeys": {}, "indexes": { "payload_preferences_key_idx": { "name": "payload_preferences_key_idx", "on": "key" }, "payload_preferences_updated_at_idx": { "name": "payload_preferences_updated_at_idx", "on": "updatedAt" }, "payload_preferences_created_at_idx": { "name": "payload_preferences_created_at_idx", "on": "createdAt" } } }, ``` After: ```ts "payload_preferences": { "name": "payload_preferences", "columns": { "id": { "name": "id", "type": "serial", "primaryKey": true }, "key": { "name": "key", "type": "varchar" }, "value": { "name": "value", "type": "jsonb" }, "updatedAt": { "name": "updated_at", "type": "timestamp", "defaultNow": true, "mode": "string", "notNull": true, "precision": 3, "withTimezone": true }, "createdAt": { "name": "created_at", "type": "timestamp", "defaultNow": true, "mode": "string", "notNull": true, "precision": 3, "withTimezone": true } }, "foreignKeys": {}, "indexes": { "payload_preferences_key_1_idx": { "name": "payload_preferences_key_1_idx", "on": "key" }, "payload_preferences_updated_at_1_idx": { "name": "payload_preferences_updated_at_1_idx", "on": "updatedAt" }, "payload_preferences_created_at_1_idx": { "name": "payload_preferences_created_at_1_idx", "on": "createdAt" } } }, ``` Which isn't really great for dev performance and can potentially cause errors
kendelljoseph
pushed a commit
that referenced
this pull request
Feb 21, 2025
Based on #10154 If the actual database schema is not changed (no new columns, enums, indexes, tables) - skip calling Drizzle push. This, potentially can significantly reduce overhead on reloads in development mode especially when using remote databases. If for whatever reason you need to preserve the current behavior you can use `PAYLOAD_FORCE_DRIZZLE_PUSH=true` env flag.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As we didn't reset our
adapter.indexes
state, on every HMR reload we incremented every single index name with thebuildIndexName
:payload/packages/drizzle/src/utilities/buildIndexName.ts
Lines 3 to 24 in 466f109
I found this while debugging our internal SQL schema:
Before reload:
After:
Which isn't really great for dev performance and can potentially cause errors